import EventMgr from "../../../Core/Event/EventMgr";
import SdkTool from "../../../Core/Sdk/SdkTool";
import TimerMgr from "../../../Core/Timer/TimerMgr";
import ProtoBufManager from "../../proto/ProtoBufManager";
import { common } from "../../proto/protoCmd";
import { ViewManager } from "../base/ViewManager";
import { AbstractModel } from "../socket/AbstractModel";
import { GameModels } from "../socket/GameModels";
import { SocketManager } from "../socket/SocketManager";
import ModuleWindow from "../window/ModuleWindow";
import WindowObject from "../window/WindowObject";

export class ModelRank extends AbstractModel {
    public send_ReqRankInfos(index?: number): void {
        const msg = ProtoBufManager.ins.pbSupport.ReqRankInfos.create();
        msg.PageIndex = index;
        const data = ProtoBufManager.ins.pbSupport.ReqRankInfos.encode(msg).finish();
        this.send(4000, `Support.Support.ReqRandomMateGame`, data);
        ViewManager.ins.showloading();
    }
    protected registerInterestedProtocols(): void {
        this.reg(4000, this.onRespRankInfos);
    }
    private onRespRankInfos(data: any): void {
        ViewManager.ins.removeLoading();
        const info = ProtoBufManager.ins.pbSupport.RespRankInfos.decode(data);
        if (info.ErrCode != ProtoBufManager.ins.pbCommon.ErrorCode.OK) {
            ViewManager.ins.showtips(`请求排行榜失败,错误码:` + info.ErrCode);
        } else {
            EventMgr.emit(`event_RespRankInfos`, info);
        }
    }
}